module.exports = class extends baseController{
    constructor(){
        super();
        this.fileLogic=this.loadLogic('iframe/file');
        this.router.post("/getItems",this.getItems.bind(this));
        this.router.post("/getAllFile",this.getAllFile.bind(this));
        return this.router;
    }

    /**
     * 逐级搜索目录下的文件
     * @param req
     * @param res
     * @returns {Promise<void>}
     */
    async getItems(req,res){
        let ret={};
        try{
            let rootPath=req.body.rootPath || "";//搜索的跟路径
            let isCurDir=req.body.isCurDir || 0; //是否只能选择当前目录
            let ext=req.body.ext || '';//允许的后缀文件
            let Items= await this.fileLogic.getItems(rootPath,isCurDir,ext);
            ret=this.Success(1,Items);
        }
        catch(err){
            ret=this.Error('操作失败',err);
        }
        res.json(ret);
    }

    async getAllFile(req,res){
        let ret={};
        try{
            let rootPath=req.body.rootPath || "";
            let Items= await this.fileLogic.getAllFile(rootPath);
            ret=this.Success(1,Items);
        }
        catch(err){
            ret=this.Error('操作失败',err);
        }
        res.json(ret);
    }
};